package part7threadpool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/*
 * Executors.newSingleThreadExecutor()：只有一个线程
 * */
public class ThreadPoolTest02 {

    public static void main(String[] args) {
        // 有且只有一个固定的线程
        ExecutorService threadPool = Executors.newSingleThreadExecutor();

        try {
            // 模拟有10个顾客过来银行办理业务，池子中只有1个工作人员受理业务
            for (int i = 0; i < 10; i++) {
                threadPool.execute(() -> {
                    System.out.println(Thread.currentThread().getName() + " 办理业务");
                });
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            // 用完记得关闭
            threadPool.shutdown();
        }
    }

}
